package com.wugh.fast.module.api.vo;


import com.wugh.fast.module.api.bo.BasePageQueryBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;

/**
 * @author WUGH
 * @date 2018/3/15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Accessors(chain = true)
@ApiModel("分页查询结果视图")
public class PageQueryResultVO<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("总大小")
    private Long total;
    @ApiModelProperty("当前页码")
    private Integer pageNumber;
    @ApiModelProperty("页大小")
    private Integer pageSize;
    @ApiModelProperty("总页数")
    private Integer pages;
    @ApiModelProperty("返回结果")
    private List<T> rows;
    @ApiModelProperty("分页查询的对象")
    private BasePageQueryBO queryBO;

    /**
     * 通过list上传分页对象
     *
     * @param list  集合
     * @param query 查询对象
     * @param <T>
     * @return
     */
    public static <T> PageQueryResultVO<T> of(List<T> list, BasePageQueryBO query) {
        PageQueryResultVOBuilder<T> builder = PageQueryResultVO.builder();
        return builder
                .queryBO(query)
                .rows(list)
                .pageNumber(1)
                .pages(1)
                .pageSize(1)
                .total((long) list.size()).build();
    }
}
